import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.rmi.server.ServerCloneException;
import java.util.List;
@SuppressWarnings("unchecked")
//如果确保转换是安全的可使用该注解，抑制编译器的警告
public class StudentServer {
    public static void main(String[] args) throws Exception{
        int port=8888;
        ServerSocket server=new ServerSocket(port);
        System.out.println("服务器：启动成功，等客户端连接，端口"+port);
        //
        Socket client=server.accept();
        System.out.println("服务器：客户端连接成功");
        //获取io流
        InputStream is=client.getInputStream();
        ObjectInputStream ois=new ObjectInputStream(is);
        //接收
        List<Student> list=(List<Student>)ois.readObject();
        System.out.println("服务器：已成功接收"+list.size()+"个学生对象");
        //bianlishuzu
        for(Student s:list){
            System.out.println(s);
        }
        //关闭资源
        System.out.println("服务器：即将关闭。");
        ois.close();
        is.close();
        client.close();
        server.close();

    }
}
